package yb.ecp.fast.user.web;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.user.infra.AuthCode;
import yb.ecp.fast.user.infra.BasicController;
import yb.ecp.fast.user.service.VO.WorkspaceVO;
import yb.ecp.fast.user.service.WorkspaceService;

import java.util.List;

/**
 * Created by LiChangjiang on 2017/12/26 0026.
 */

@RestController
@RequestMapping("/workspace")
public class WorkSpaceController extends BasicController
{
    @Autowired
    WorkspaceService workspaceService;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有工作空间")
    public ActionResult listSpace()
    {
        return actionResult(workspaceService.queryList());
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "增加工作空间")
    public ActionResult insert(@RequestBody WorkspaceVO workspaceVO) throws Exception
    {
        return actionResult(workspaceService.insert(workspaceVO));
    }

    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    @ApiOperation(value = "批量删除工作空间")
    public ActionResult remove(@RequestBody List<String> ids)
    {
        return actionResult(workspaceService.removeByIds(ids));
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改工作空间信息")
    public ActionResult update(@RequestBody WorkspaceVO workspaceVO)
    {
        return actionResult(workspaceService.update(workspaceVO));
    }

    @RequestMapping(value = "/item", method = RequestMethod.GET)
    @ApiOperation(value = "查看工作空间信息")
    public ActionResult item(@RequestParam("id")  String id)
    {
        return actionResult(workspaceService.item(id));
    }

    @RequestMapping(value = "/updateTemplate", method = RequestMethod.POST)
    @ApiOperation(value = "修改工作空间对应的权限模板ID")
    public ActionResult updateTemplate(@RequestParam("workspaceId")  String workspaceId,@RequestParam("templateId")  String templateId)
    {
        return actionResult(workspaceService.updateTemplate(workspaceId,templateId));
    }
    @RequestMapping(value = "/remove", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除企业工作空间")
    public ActionResult remove(@RequestParam("workspaceId")  String workspaceId)
    {
        return actionResult(workspaceService.remove(workspaceId));
    }
    
    @RequestMapping(value = "/lock", method = RequestMethod.POST)
    @ApiOperation(value = "冻结锁定企业工作空间")
    public ActionResult lock(@RequestParam("workspaceId")  String workspaceId) {
    	return actionResult(workspaceService.lock(workspaceId));
    }
    
    @RequestMapping(value = "/unlock", method = RequestMethod.POST)
    @ApiOperation(value = "解锁企业工作空间")
    public ActionResult unlock(@RequestParam("workspaceId")  String workspaceId) {
    	return actionResult(workspaceService.unlock(workspaceId));
    }

}
